package com.example.test_004;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 确保正确导入 EditText 和 TextView.OnEditorActionListener
        EditText searchBar = findViewById(R.id.searchBar);
        if (searchBar != null) {
            searchBar.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == android.view.inputmethod.EditorInfo.IME_ACTION_DONE
                            || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                        // 阻止回车键的默认行为
                        return true;
                    }
                    return false;
                }
            });
        } else {
            // 如果未找到 searchBar 控件，打印日志提示
            System.out.println("AAAsearchBar 控件未在布局中找到，请检查 activity_main.xml");
        }
    }
}
